import Sequelize from 'sequelize'
import configReader from '../../utils/configReader'

const { dbConfig: { host, port, userName, password, dbName } } = new configReader("./server/config/index.json").get("dev");
// const { dbConfig: { host, port, userName, password, dbName } } = new configReader("./config/index.json").get("dev");


const db = new Sequelize(dbName, userName, password, {
    host,
    port,
    dialect: 'mysql',
    define: {
        timestamps: false
    },
    pool: {
        max: 10,
        min: 0,
        acquire: 30000,
        idle: 10000
    },
    operatorsAliases: false
});

db.authenticate()
    .then(() => {
        console.log('Connection has been established successfully.');
    })
    .catch(err => {
        console.error('Unable to connect to the database:', err);
    });

export {
    Sequelize,
    db
};
